<template>
	<view>
        <u-popup :show="show" mode="bottom" :round="10" @close="closeShow" >
            <div class="popupTitle">取消订单</div>
			<div class="popup-con">
				<u--form labelPosition="left" :model="form" :rules="rules" ref="form" labelWidth="100" errorType="toast">
					<u-form-item required label="取消原因" prop="cancelReason" borderBottom @click="show2 = true">
						<u--input v-model="form.cancelReason" disabled disabledColor="#ffffff" placeholder="请选择原因" border="none" inputAlign="right" style="pointer-events: none"></u--input>
						<u-icon slot="right" name="arrow-right" ></u-icon>
					</u-form-item>
					<u-form-item label="备注" :borderBottom="false" labelPosition="top" prop="cancelRemark">
						<div style="margin-top:10px;width:100%" >
							<u--textarea v-model="form.cancelRemark" placeholder="请输入内容" ></u--textarea>
						</div>	
					</u-form-item>
				</u--form>
			</div>
			<div class="u-flex popup-bottom">
				<u-button text="取消"  shape="circle" @click="closeShow"></u-button>
				<u-button text="确认"  shape="circle" type="primary" @click="saveForm" :loading="btnLoading"></u-button>
			</div>
			<u-action-sheet
					:show="show2"
					:actions="actions"
					title="请选择取消原因"
					description="选择其它时，备注必填"
					@close="show2 = false"
					@select="selectItem"
			>
			</u-action-sheet>
        </u-popup>
	</view>
</template>
<script>


import {editOrder,orderCancelData} from '@/config/api.js'
import store from '@/store';

const defaultForm={
	     orderId:'',
		 cancelReason:'',
		 cancelRemark:'',
    };
export default {
    name: 'cancelOrder',
    computed: {
    	
		
    },
	data() {
		return {
          show:false,
		  value1:'',
		  show2:false,
		  actions:[],
	      form:JSON.parse(JSON.stringify(defaultForm)),
		  rules: {
		  	cancelReason: [{
		  			required: true,
		  			message: '请选择取消原因',
		  			// 可以单个或者同时写两个触发验证方式
		  			trigger: ['blur', 'change']
		  		}],
			cancelRemark:[{
				validator: (rule, value, callback) => {
					console.log("value",value)
					console.log("this.form.cancelReason",this.form.cancelReason)
					// 上面有说，返回true表示校验通过，返回false表示不通过
					// uni.$u.test.mobile()就是返回true或者false的
					if(this.form.cancelReason == '其它' && value == ''){
						return false
					}else{
						return true
					}
				},
				message: '选择其它时，备注必填',
				// 触发器可以同时用blur和change
				trigger: ['change','blur'],
			}]
		  },
		  btnLoading:false
		 
		}
	},
    watch:{

    },
	created() {
	
	},
	methods: {
		init(item){
			this.show = true;
			this.form = JSON.parse(JSON.stringify(defaultForm));
			this.form.orderId = item.orderId;
			setTimeout(()=>{
				// #ifdef MP
				this.$refs.form.setRules(this.rules)
				// #endif
				},1000)	
				orderCancelData({reasonType:'cancel_order'}).then((res)=>{
					this.actions = res.list
				})
		},
		selectItem(e){
			this.form.cancelReason = e.name
			this.$refs.form.validateField('cancelReason')
		},
       saveForm(){
		   this.$refs.form.validate().then(res => {
			   this.btnLoading = true;
			   let  data = JSON.parse(JSON.stringify(this.form));
			   data.operationType = 'buyerCancel'
				 editOrder(data).then(()=>{
					   this.btnLoading = false;
					   this.closeShow();
					   this.$emit('refresh')
				 }).catch(()=>{
					   this.btnLoading = false;
				 })
		   }).catch(errors => {
		   	
		   })
	   },
	   closeShow(){
		   this.show = false
	   }
        
		
		
        
       
        
        
        
        
      
        
	}
};
</script>

<style lang="scss" scoped>
@import '@/style/common.scss';
.popupTitle{
	font-size:$b-font;
	font-weight: bold;
	text-align: center;
	line-height: 50px;
}
   .popup-con{
    	padding:0 16px 16px 16px;
    	.popup-block-pay{
    		text-align: center;
    		padding:20px;
    		.price-sub-title{
    			font-size:$s-font;
    			color:$g-font-color;
    			line-height: 30px;
    		}
    		.price-big-title{
    			font-size: 22px;
    			color:$theme-color;
    			font-weight:bold;
    			margin-top:10px;
    		}
    	}
    	.popup-label{
    		line-height: 40px;
    		font-size:$m-font;
    		color:$g-font-color;
    		@include flexbox(space-between,center)
    	}
    	.img-div{
    		width:210px;
    		height:210px;
    		border:1px solid $border-color;
    		margin:0 auto;
    		background: #f4f5f7;
    	}
        .send-list{
    		padding-top:$marginSpace;
    		.send-item{
    			border-radius: 8px;
    			padding:12px;
    			box-shadow: 0 0 5px rgba(0,0,0,0.1);
    			margin-bottom:$marginSpace;
    			.send-top{
    				@include flexbox(flex-start,flex-start);
    				font-size:$m-font;
    				.name{
    					padding-right:12px;
    					flex:1
    				}
    				.num{
    					font-weight: bold;
    					color:$theme-color
    				}
    			}
    			.send-middle{
    				font-size:$s-font;
    				color:$g-font-color;
    				line-height: 18px;
    				margin-top:5px;
    			}
    			.send-bottom{
    				text-align: right;
    				font-size:$s-font;
    				margin-top:16px
    			}
    		}
    	}
    	.category-list{
    		padding:36rpx 0;
    		.list-item{
    			@include flexbox(flex-start,flex-start);
    			margin-bottom:20rpx;
    			.item-title{
    				width: 126rpx;
    				height: 52rpx;
    				background: rgba(255,255,255,0.39);
    				border: 1px solid #B8B8B8;
    				border-radius: 9rpx;
    				font-size:$m-font;
    				text-align: center;
    				line-height: 52rpx;
    			}
    			.item-list{
    				padding-left:30rpx;
    				width:calc(100% - 126rpx);
    				overflow: hidden;
    				.item-ename{
    					font-size:$s-font;
    					color: #929292;
    					line-height: 52rpx;
    					width: 170rpx;
    					@include textoverflow(1);
    					float:left;
    				}
    			}
    		}
    	}
    	.goodsSn-list{
    		border: 1px solid #DEDEDE;
    		padding:0 10px;
    		font-size:$s-font;
    		margin-top:15px;
    		padding-bottom:10px;
    		.list-cell{
    			border-bottom:1px solid #DEDEDE;
    			@include flexbox(space-between,center);
    			line-height: 60rpx;
    			height:60rpx;
    		}
    		.list-cell:first-child{
    			
    		}
    	}
    	.audio-text{
    		font-size: 34rpx;
    		line-height: 48rpx;
    		color: #414141;
    		text-align: center;
    		padding-top:100rpx;
    	}
    	.audio-dh{
    		@include flexbox(space-between,center);
    	}
    
    }
    .popup-bottom{
    	background: #fff;
    	margin-top:10px;
    	padding:16px;
    }
    .popup-bottom-fixed{
    	position: fixed;
    	width:100%;
    	padding:16px;
    	box-sizing: border-box;
    	bottom:0
    }
    
    

</style>
